package com.mes.designer;

import org.hibernate.Query;
import org.openbravo.base.exception.OBException;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBDal;
import org.openbravo.database.ConnectionProvider;
import org.openbravo.erpCommon.utility.Utility;
import org.openbravo.service.db.DalConnectionProvider;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * bom工具类
 * 
 * @author Administrator
 *
 */
public class EmesBomDesigner {
	/**
	 * 根据单一的产品
	 * 
	 * @param ID
	 * @param date
	 * @return
	 */
	public List GetActiveBOMID(String ProID, Date date) {
		if (ProID == null || "".equalsIgnoreCase(ProID.trim())) {
			String language = OBContext.getOBContext().getLanguage().getLanguage();
			ConnectionProvider conn = new DalConnectionProvider(false);
			throw new OBException(Utility.messageBD(conn, "您必须指定一个产品ID以供查询。请仔细检查。", language));
		}
		List list = new ArrayList();
		list = null;
		String hql = "";
		hql += "select ep.id from Emes_PBOM ep where ep.product.id=:prodId";
		if (date != null) {
			hql += "and :date >=activityDateFrom and :date <=activityDateTo";
			Query query = OBDal.getInstance().getSession().createQuery(hql);
			query.setString("prodId", ProID);
			query.setTime("date", date);
			list = query.list();
		} else {
			Query query = OBDal.getInstance().getSession().createQuery(hql);
			query.setString("prodId", ProID);
			list = query.list();
		}
		return list;
	}
}
